import pandas as pd


def read_update(source):
    # 方式一
    # 获取单个列
    print(source["name"])
    # 获取多个列
    print(source[["name", "age"]])
    # 获取行通过切片获取单行和多行
    print(source[0:1])
    print(source["one":"one"])


def read_loc_iloc(source):
    # 方式二：loc与iloc
    # source.loc(参数一,参数二) 标签索引
    # 参数一：可以是单个值，可以是列表，可以是切片
    print(source.loc["one", "name"])
    print(source.loc[["one", "two"], "name"])
    print(source.loc[:"two", "name"])

    # source.iloc(参数一,参数二) 整数索引
    # 参数一：可以是单个值，可以是列表，可以是切片
    print(source.iloc[0, 0])
    print(source.iloc[[0, 1], 0])
    print(source.iloc[:1, 0])

    source.iloc[[0, 1], 0] = "commonplace"


if __name__ == '__main__':
    data = {"name": {"one": "小明", "two": "小红", "three": "小蓝"},
            "age": {"one": 18, "two": 19, "three": 20},
            "height": {"one": 188, "two": 189, "three": 160}
            }
    frame = pd.DataFrame(data)
    # read_update(frame)
    read_loc_iloc(frame)
    print(frame)
